﻿@model  WaiGaoQiaoWeb.Models.ArticleUnitVM
@{
    ViewBag.Title = "AUIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("main", "flexigrid", "tree")
    <script type="text/javascript">
        var maiheight = document.documentElement.clientHeight;
        $(document).ready(function () {
            var mainWidth = document.documentElement.clientWidth ; // 减去边框和左边的宽度
            var otherpm = 143;
            var gh = maiheight - otherpm;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetWork_ArticleUnitList")',
                dataType: 'json',
                colModel: [
                    { display: 'ID', name: 'ID', width: 50, sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '物资名称', name: 'ArticleNO', width: 80, sortable: false, hide: false, align: 'left', iskey: true },
                    { display: '物资规格', name: 'ArticleName', width: 200, sortable: false, hide: false, align: 'left', iskey: true },
                    { display: '备注', name: 'ArticleUnit', width: 80, sortable: false, hide: false, align: 'left', iskey: true }

                ],
                buttons: [
						    { name: 'Add', displayname: "新建", title: "新建物资规格", bclass: 'add InsertClass', onpress: toolbarItem_onclick },
							{ name: 'Edit', displayname: "修改", title: "修改物资规格", bclass: 'edit UpdateClass', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除物资规格", bclass: 'delete DeleteClass', onpress: toolbarItem_onclick },
							{ separator: true }
						 ],
                sortname: "DispOrder",
                sortorder: "asc",
                title: false,
                singleselected: false,
                usepager: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 20, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                rowbinddata: true
            };

            var grid = $("#ConGoodList").flexigrid(option);


            //查询
            $("#btnQueryList").click(function () {
            $('#ConGoodList').flexOptions({
                    newp: 0,
                    query: $.trim($("#ddlArticle").val())
                }).flexReload();
            });

        });

        function refresh() {
            $("#ConGoodList").flexReload();
            
        }
       //新增，删除，修改
        function toolbarItem_onclick(cmd, grid) {
            if (cmd == "Add") {
                OpenModelWindow('@Url.Action("Add")', { width: 520, height: 210, caption: "物资规格添加",
                    onclose: refresh
                });
            }
            else if (cmd == "Edit") {
                if ($('.trSelected', grid).length == 0) {
                    showErrorTip("请选择要编辑的行！", { left: 400, top: 2 }, true, 3000);
                    return false;
                }

                if ($('.trSelected', grid).length > 1) {
                    showErrorTip("只能选择一行！", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
              
                var items = $('.trSelected', grid);
                var Id = items[0].id.substr(3);
                OpenModelWindow('@Url.Action("Add")?Id=' + Id,
                                   { width: 520, height: 210, caption: "编辑物资规格",
                                       onclose: function () {
                                       refresh();
                                       }
                                   });
            }
            else if (cmd = "Delete") {
                if ($('.trSelected', grid).length == 0) {
                    showErrorTip("请选择要删除的行！", { left: 400, top: 2 }, true, 3000);
                    return false;
                }

               
                if (confirm("确定要删除吗?")) {
                    var ids = "";
                    var items = $('.trSelected', grid);
                    for (i = 0; i < items.length; i++) {
                        ids = items[i].id.substr(3);
                        $.ajax({
                                url: '@Url.Action("Delete")',
                                type: "POST",
                                data: { Id: ids },
                                success: function (callback) {
                                    if (callback) {
                                        showLoadingMsg("删除成功", { left: 400, top: 2 }, true, 3000);
                                        refresh();
                                        }
                                        else
                                        {
                                          showLoadingMsg("操作失败", { left: 400, top: 2 }, true, 3000);
                                        }
                                        
                                    }
                              }); // end $.ajax
                  } //for                    
                }
            }
        }

    </script>
}
<div id="container">
   
         <div id="title" class="title">
             物资规格管理</div>
               <div id="divQuery" class="title">
               <table>
               <tr >
               <td> 物资名称： @Html.DropDownList("ddlArticle", ViewBag.AD as IEnumerable<SelectListItem>, new {@style="width:180;" })</td>
               <td> <a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a></td>
               </tr>
               </table>
              
            
              
               </div>
        <table id="ConGoodList" style="display: none;">
        </table>
   
    @Html.HiddenFor(model => model.ID)
    
</div>



